//
//  DialSettingViewController.m
//  yixintong
//
//  Created by longzhiyuan on 15/6/6.
//
//

#import "DialSettingViewController.h"

@interface DialSettingViewController ()
@property (retain, nonatomic) IBOutlet UISwitch *switchSound;
@property (retain, nonatomic) IBOutlet UISwitch *switchShowPhoneNum;

@end

@implementation DialSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}
-(void)viewDidAppear:(BOOL)animated
{
    
    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"swithState"] isEqualToString:@"YES"])
    {
        [self.switchSound setOn:YES];
    }else
    {
        [self.switchSound setOn:NO];
    }
    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"showNum"] isEqualToString:@"NO"])
    {
        [self.switchShowPhoneNum setOn:NO];
    }else
    {
        [self.switchShowPhoneNum setOn:YES];
    }
    [super viewDidAppear:animated];
}
- (IBAction)switchSound_click:(UISwitch *)sender
{
    if (sender.on)
    {
        NSUserDefaults* defaults=[NSUserDefaults standardUserDefaults];
        [defaults setObject:@"YES" forKey:@"swithState"];
        [defaults synchronize];
    }else
    {
        NSUserDefaults* defaults=[NSUserDefaults standardUserDefaults];
        [defaults setObject:@"NO" forKey:@"swithState"];
        [defaults synchronize];
    }
    /*
    if (sender.selected)
    {
        [self showAlert:@"你是否要关闭拨号提示音" tag:900];
    }else{
        [self showAlert:@"你是否要开启拨号提示音" tag:900];
    }
     */
    
}
- (IBAction)switchShowPhoneNum_click:(UISwitch *)sender
{
    if (sender.on)
    {
        NSUserDefaults* defaults=[NSUserDefaults standardUserDefaults];
        [defaults setObject:@"YES" forKey:@"showNum"];
        [defaults synchronize];
    }else
    {
        NSUserDefaults* defaults=[NSUserDefaults standardUserDefaults];
        [defaults setObject:@"NO" forKey:@"showNum"];
        [defaults synchronize];
    }
    /*
    if (sender.selected)
    {
        [self showAlert:@"在对方手机不显示你的号码" tag:1000];
    }else{
        [self showAlert:@"在对方手机里显示你的号码" tag:1000];
    }
     */
}
/*
-(void)showAlert:(NSString*)msg tag:(NSInteger)tagIndex
{
    
    UIAlertView* alert=[[UIAlertView alloc]initWithTitle:@"提醒" message:msg delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定",@"取消", nil];alert.tag=tagIndex;
    [alert show];
    [alert release];
    
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag==900)
    {
        if (buttonIndex==0)
        {
            if (self.switchSound.selected)
            {
                NSUserDefaults* defaults=[NSUserDefaults standardUserDefaults];
                [defaults setObject:@"YES" forKey:@"swithState"];
                [defaults synchronize];
            }else
            {
                NSUserDefaults* defaults=[NSUserDefaults standardUserDefaults];
                [defaults setObject:@"NO" forKey:@"swithState"];
                [defaults synchronize];
            }
        }
        
    }else if (alertView.tag==1000)
    {
        if (buttonIndex==0)
        {
            if (self.switchShowPhoneNum.selected)
            {
                NSUserDefaults* defaults=[NSUserDefaults standardUserDefaults];
                [defaults setObject:@"YES" forKey:@"showNum"];
                [defaults synchronize];
            }else
            {
                NSUserDefaults* defaults=[NSUserDefaults standardUserDefaults];
                [defaults setObject:@"NO" forKey:@"showNum"];
                [defaults synchronize];
            }
        }
    }
    
}
*/
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)dealloc {
    [_switchSound release];
    [_switchShowPhoneNum release];
    [super dealloc];
}
- (void)viewDidUnload {
    [self setSwitchSound:nil];
    [self setSwitchShowPhoneNum:nil];
    [super viewDidUnload];
}
@end
